/********************************** (C) COPYRIGHT *******************************
* File Name          : main.c
* Author             : WCH
* Version            : V1.0.0
* Date               : 2021/06/06
* Description        : Main program body.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for 
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/

/*
 *@Note
 USART Print debugging routine:
 USART1_Tx(PA9).
 This example demonstrates using USART1(PA9) as a print debug port output.

*/

#include "debug.h"
#include "drv_u8g2.h"

/* Global typedef */

/* Global define */

/* Global Variable */
u8g2_t u8g2;

/*********************************************************************
 * @fn      main
 *
 * @brief   Main program.
 *
 * @return  none
 */
int main(void)
{
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
    SystemCoreClockUpdate();
    Delay_Init();
    USART_Printf_Init(115200);
    printf("SystemClk:%d\r\n", SystemCoreClock);
    printf("ChipID:%08x\r\n", DBGMCU_GetCHIPID());
    printf("This is printf example\r\n");

    OLED_Init();
    u8g2_Setup_ssd1306_i2c_128x64_noname_f(
        &u8g2,
        U8G2_R0,
        //u8x8_byte_sw_i2c,
        u8x8_byte_i2c,
        u8x8_gpio_and_delay); // init u8g2 structure
    u8x8_SetI2CAddress(&u8g2.u8x8, 0x78);

    printf("u8g2_InitDisplay\r\n");
    u8g2_InitDisplay(&u8g2); // send init sequence to the display, display is in sleep mode after this,
    u8g2_SetContrast(&u8g2, 0xFF);

    printf("u8g2_SetPowerSave\r\n");
    u8g2_SetPowerSave(&u8g2, 0); // wake up display
    u8g2_ClearDisplay(&u8g2);

    u8g2_SetFont(&u8g2, u8g2_font_t0_11_tf);
    // set the font coordinates to the upper left corner
    u8g2_SetFontPosTop(&u8g2);

    u8g2_SetDrawColor(&u8g2, 0);
    u8g2_DrawRBox(&u8g2, 3, 3, 122, 58, 7);
    u8g2_SetDrawColor(&u8g2, 1);
    u8g2_DrawRFrame(&u8g2, 3, 3, 122, 58, 7);
    u8g2_DrawStr(&u8g2, 8, 8, "hello world");
    u8g2_SendBuffer(&u8g2);

    while (1) {
    }
}
